{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The autoreload extension is already loaded. To reload it, use:\n",
      "  %reload_ext autoreload\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.insert(0, '../')\n",
    "\n",
    "from minisom import MiniSom\n",
    "\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "%load_ext autoreload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r",
      " [   0 / 100 ]   0% - ? it/s\r",
      " [   0 / 100 ]   0% - ? it/s\r",
      " [   1 / 100 ]   1% - 0:00:00 left \r",
      " [   2 / 100 ]   2% - 0:00:00 left \r",
      " [   3 / 100 ]   3% - 0:00:00 left \r",
      " [   4 / 100 ]   4% - 0:00:00 left \r",
      " [   5 / 100 ]   5% - 0:00:00 left \r",
      " [   6 / 100 ]   6% - 0:00:00 left \r",
      " [   7 / 100 ]   7% - 0:00:00 left \r",
      " [   8 / 100 ]   8% - 0:00:00 left \r",
      " [   9 / 100 ]   9% - 0:00:00 left \r",
      " [  10 / 100 ]  10% - 0:00:00 left \r",
      " [  11 / 100 ]  11% - 0:00:00 left \r",
      " [  12 / 100 ]  12% - 0:00:00 left \r",
      " [  13 / 100 ]  13% - 0:00:00 left \r",
      " [  14 / 100 ]  14% - 0:00:00 left \r",
      " [  15 / 100 ]  15% - 0:00:00 left \r",
      " [  16 / 100 ]  16% - 0:00:00 left \r",
      " [  17 / 100 ]  17% - 0:00:00 left \r",
      " [  18 / 100 ]  18% - 0:00:00 left \r",
      " [  19 / 100 ]  19% - 0:00:00 left \r",
      " [  20 / 100 ]  20% - 0:00:00 left \r",
      " [  21 / 100 ]  21% - 0:00:00 left \r",
      " [  22 / 100 ]  22% - 0:00:00 left \r",
      " [  23 / 100 ]  23% - 0:00:00 left \r",
      " [  24 / 100 ]  24% - 0:00:00 left \r",
      " [  25 / 100 ]  25% - 0:00:00 left \r",
      " [  26 / 100 ]  26% - 0:00:00 left \r",
      " [  27 / 100 ]  27% - 0:00:00 left \r",
      " [  28 / 100 ]  28% - 0:00:00 left \r",
      " [  29 / 100 ]  29% - 0:00:00 left \r",
      " [  30 / 100 ]  30% - 0:00:00 left \r",
      " [  31 / 100 ]  31% - 0:00:00 left \r",
      " [  32 / 100 ]  32% - 0:00:00 left \r",
      " [  33 / 100 ]  33% - 0:00:00 left \r",
      " [  34 / 100 ]  34% - 0:00:00 left \r",
      " [  35 / 100 ]  35% - 0:00:00 left \r",
      " [  36 / 100 ]  36% - 0:00:00 left \r",
      " [  37 / 100 ]  37% - 0:00:00 left \r",
      " [  38 / 100 ]  38% - 0:00:00 left \r",
      " [  39 / 100 ]  39% - 0:00:00 left \r",
      " [  40 / 100 ]  40% - 0:00:00 left \r",
      " [  41 / 100 ]  41% - 0:00:00 left \r",
      " [  42 / 100 ]  42% - 0:00:00 left \r",
      " [  43 / 100 ]  43% - 0:00:00 left \r",
      " [  44 / 100 ]  44% - 0:00:00 left \r",
      " [  45 / 100 ]  45% - 0:00:00 left \r",
      " [  46 / 100 ]  46% - 0:00:00 left \r",
      " [  47 / 100 ]  47% - 0:00:00 left \r",
      " [  48 / 100 ]  48% - 0:00:00 left \r",
      " [  49 / 100 ]  49% - 0:00:00 left \r",
      " [  50 / 100 ]  50% - 0:00:00 left \r",
      " [  51 / 100 ]  51% - 0:00:00 left \r",
      " [  52 / 100 ]  52% - 0:00:00 left \r",
      " [  53 / 100 ]  53% - 0:00:00 left \r",
      " [  54 / 100 ]  54% - 0:00:00 left \r",
      " [  55 / 100 ]  55% - 0:00:00 left \r",
      " [  56 / 100 ]  56% - 0:00:00 left \r",
      " [  57 / 100 ]  57% - 0:00:00 left \r",
      " [  58 / 100 ]  58% - 0:00:00 left \r",
      " [  59 / 100 ]  59% - 0:00:00 left \r",
      " [  60 / 100 ]  60% - 0:00:00 left \r",
      " [  61 / 100 ]  61% - 0:00:00 left \r",
      " [  62 / 100 ]  62% - 0:00:00 left \r",
      " [  63 / 100 ]  63% - 0:00:00 left \r",
      " [  64 / 100 ]  64% - 0:00:00 left \r",
      " [  65 / 100 ]  65% - 0:00:00 left \r",
      " [  66 / 100 ]  66% - 0:00:00 left \r",
      " [  67 / 100 ]  67% - 0:00:00 left \r",
      " [  68 / 100 ]  68% - 0:00:00 left \r",
      " [  69 / 100 ]  69% - 0:00:00 left \r",
      " [  70 / 100 ]  70% - 0:00:00 left \r",
      " [  71 / 100 ]  71% - 0:00:00 left \r",
      " [  72 / 100 ]  72% - 0:00:00 left \r",
      " [  73 / 100 ]  73% - 0:00:00 left \r",
      " [  74 / 100 ]  74% - 0:00:00 left \r",
      " [  75 / 100 ]  75% - 0:00:00 left \r",
      " [  76 / 100 ]  76% - 0:00:00 left \r",
      " [  77 / 100 ]  77% - 0:00:00 left \r",
      " [  78 / 100 ]  78% - 0:00:00 left \r",
      " [  79 / 100 ]  79% - 0:00:00 left \r",
      " [  80 / 100 ]  80% - 0:00:00 left \r",
      " [  81 / 100 ]  81% - 0:00:00 left \r",
      " [  82 / 100 ]  82% - 0:00:00 left \r",
      " [  83 / 100 ]  83% - 0:00:00 left \r",
      " [  84 / 100 ]  84% - 0:00:00 left \r",
      " [  85 / 100 ]  85% - 0:00:00 left \r",
      " [  86 / 100 ]  86% - 0:00:00 left \r",
      " [  87 / 100 ]  87% - 0:00:00 left \r",
      " [  88 / 100 ]  88% - 0:00:00 left \r",
      " [  89 / 100 ]  89% - 0:00:00 left \r",
      " [  90 / 100 ]  90% - 0:00:00 left \r",
      " [  91 / 100 ]  91% - 0:00:00 left \r",
      " [  92 / 100 ]  92% - 0:00:00 left \r",
      " [  93 / 100 ]  93% - 0:00:00 left \r",
      " [  94 / 100 ]  94% - 0:00:00 left \r",
      " [  95 / 100 ]  95% - 0:00:00 left \r",
      " [  96 / 100 ]  96% - 0:00:00 left \r",
      " [  97 / 100 ]  97% - 0:00:00 left \r",
      " [  98 / 100 ]  98% - 0:00:00 left \r",
      " [  99 / 100 ]  99% - 0:00:00 left \r",
      " [ 100 / 100 ] 100% - 0:00:00 left \n",
      " quantization error: 0.8499230331693959\n",
      " topographic error: 0.4\n"
     ]
    }
   ],
   "source": [
    "data = np.genfromtxt('iris.csv', delimiter=',', usecols=(0, 1, 2, 3))\n",
    "data = data[:, :2] # using only the first two columns\n",
    "\n",
    "# data normalization\n",
    "data = data -  np.mean(data, axis=0)\n",
    "data /= np.std(data)\n",
    "\n",
    "# Initialization and training\n",
    "som_shape = (1, 3)\n",
    "som = MiniSom(som_shape[0], som_shape[1], 2, sigma=.35, learning_rate=.5,\n",
    "              neighborhood_function='gaussian', random_seed=10)\n",
    "\n",
    "som.pca_weights_init(data)\n",
    "som.train_batch(data, 100, verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "# each neuron represents a cluster\n",
    "winner_coordinates = np.array([som.winner(x) for x in data]).T\n",
    "# with np.ravel_multi_index we convert the bidimensional\n",
    "# coordinates to a monodimensional index\n",
    "cluster_index = np.ravel_multi_index(winner_coordinates, som_shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1149b14f0>"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAgAElEQVR4nO3df3RU9Zn48feTTBJCAioJLi0RIta1BsqPShC0KkFbFD26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Ywl/F5U9bLB3heRhcBVwKWagQsYos0vyxwAzuj1uiK8zXiciBQQSva/VNX/Tnc8qaKqR0SkkdD3Ma4kfLukEyMRuRz4BnC1qranOx4T1TbgbBE5U0QKgRuAjWmOyUQhobub3w/sUdUfpTsep4nIyO4KPxEpBj4N/Mmt41vCj91PgWHA70Vkh4jcm+6AnCQic0WkGZgB/E5Enk53TMkIf8F+O/A0oS/+HlXVXemNyhki8l/AVuAcEWkWkVvSHZODLgRuAmaF/3+2Q0TmpDsoB30EaBSR1widlPxeVZ906+DWWsEYY3KEneEbY0yOsIRvjDE5whK+McbkCEv4xhiTIyzhG2NMjrCEb4wxOcISvjHG5Ij/D587tFXhcnjMAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plotting the clusters using the first 2 dimentions of the data\n",
    "for c in np.unique(cluster_index):\n",
    "    plt.scatter(data[cluster_index == c, 0],\n",
    "                data[cluster_index == c,1], label='cluster='+str(c), alpha=.7)\n",
    "\n",
    "# plotting centroids\n",
    "for centroid in som.get_weights():\n",
    "    plt.scatter(centroid[:, 0], centroid[:, 1], marker='x', \n",
    "                s=80, linewidths=35, color='k', label='centroid')\n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
